package io.leo.leoui.dialogs;

import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

import static android.content.Context.INPUT_METHOD_SERVICE;

public class RoundEditTextDialog extends RoundDialog{
    private Context context;
    private CharSequence charSequence;
    private EditText editText;

    public RoundEditTextDialog(Context context){
        this(context,"",false);
    }
    public RoundEditTextDialog(Context context,String hint,boolean singleLine) {
        super(context);
        this.context = context;
        editText = new EditText(context);
        editText.setTextColor(0xff3e3e3e);
        editText.setTextSize(15);
        editText.setGravity(Gravity.TOP);
        editText.setSingleLine(singleLine);
        editText.setHint(hint);
        editText.setBackgroundColor(0xffffff);
        setView(editText);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void setHint(CharSequence charSequence){
        this.editText.setHint(charSequence);
    }

    public String getText(){
        return String.valueOf(editText.getText());
    }
    public void setText(CharSequence charSequence){this.editText.setText(charSequence);}
    public void selectAll(){
        this.editText.selectAll();
    }

    @Override
    public void show() {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        editText.setFocusable(true);
        editText.setFocusableInTouchMode(true);
        editText.requestFocus();
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
                |WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        super.show();
    }
}
